package com.example.luge.composedemo.viewmodel

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Description
import androidx.compose.material.icons.filled.SmartDisplay
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.example.luge.composedemo.model.Category
import com.example.luge.composedemo.model.DataType
import com.example.luge.composedemo.model.SwiperEntity

/***
 *  应该和flow 协程 相结合 去获取数据 给到前端
 * @property categories List<Category>
 * @property categoryIndex Int
 * @property types List<DataType>
 * @property currentTypeIndex Int
 * @property showArticleList Boolean
 * @property swiperData List<SwiperEntity>
 * @property notifications List<String>
 */
class MainViewModel : ViewModel() {


    //分类数据
    val categories by mutableStateOf(
        listOf(
            Category("政治"),
            Category("数学"),
            Category("英语"),
            Category("专业课")
        )
    )

    //当前分类下标
    var categoryIndex by mutableStateOf(0)
        private set


    /**
     * 更新分类下标
     *
     * @param index
     */
    fun updateCategoryIndex(index: Int) {
        categoryIndex = index
    }


    //类型数据
    val types by mutableStateOf(
        listOf(
            DataType("科大资讯", Icons.Default.Description),
            DataType("计算机视频课程", Icons.Default.SmartDisplay)
        )
    )

    //当前类型下标
    var currentTypeIndex by mutableStateOf(0)
        private set

    //是否文章列表
    var showArticleList by mutableStateOf(true)
        private set

    /**
     * 更新类型下标
     *
     * @param index
     */
    fun updateTypeIndex(index: Int) {
        currentTypeIndex = index
        showArticleList = currentTypeIndex == 0
    }

    //轮播图数据
    val swiperData = listOf(
        SwiperEntity(""),
        SwiperEntity("https://www.ustc.edu.cn/__local/5/8C/ED/6DA101442E3160ADC16BC8F3F5C_F2E169D2_B4ED.jpg?e=.jpg"),
        SwiperEntity("https://www.ustc.edu.cn/__local/4/E3/18/0697934029B2F2FDC8D77410A26_FDE0C113_121C5.jpg?e=.jpg"),
        SwiperEntity("https://zsb.ustc.edu.cn/2023/0610/c13073a607077/page.htm"),
        SwiperEntity("https://zsb.ustc.edu.cn/_upload/article/images/44/91/e1ef01b347d0b7f2caecafea9b29/73c350d3-1254-4228-888e-b72e2f54f714.jpg")
    )

    //通知数据
    val notifications = listOf(
        "关于公布第八届材料创新、设计及应用大赛获奖名单的通知",
        "关于公布第十九届程序设计竞赛获奖名单的通知",
        "关于公布第十二届大学生节能减排社会实践与科技竞赛获奖名单的通知",
        "关于公布第二十二届数学竞赛获奖名单的通知",
        "教务处关于2023年暑假工作安排的通知"
    )
}